package com.wnhz.work.yz.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.wnhz.work.yz.R;
import com.wnhz.work.yz.bean.ProjectChildBean;

import org.xutils.x;

import java.util.List;

/**
 * Created by admin on 2017/1/22.
 */
public class ProjectOrder2Adapter extends BaseAdapter {
    private Context context;
    private List<ProjectChildBean> dataList;

    public ProjectOrder2Adapter(Context context, List<ProjectChildBean> dataList) {
        this.context = context;
        this.dataList = dataList;
    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ProjectOrderViewHolder viewHolder = new ProjectOrderViewHolder();
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.project_order_item, null);
            viewHolder.iv_img = (ImageView) convertView.findViewById(R.id.iv_img);
            viewHolder.tv_goods_name = (TextView) convertView.findViewById(R.id.tv_goods_name);
            viewHolder.tv_sku_info = (TextView) convertView.findViewById(R.id.tv_sku_info);
            viewHolder.tv_product = (TextView) convertView.findViewById(R.id.tv_product);
            viewHolder.tv_goods_type = (TextView) convertView.findViewById(R.id.tv_goods_type);
            viewHolder.tv_price = (TextView) convertView.findViewById(R.id.tv_price);
            viewHolder.tv_goods_number = (TextView) convertView.findViewById(R.id.tv_goods_number);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ProjectOrderViewHolder) convertView.getTag();

        }
        x.image().bind(viewHolder.iv_img, dataList.get(position).getGoods_pic());
        viewHolder.tv_goods_name.setText(dataList.get(position).getGoods_name());
//        if (!"整体浴室".equals(dataList.get(position).getPackage_cate())) {
//            viewHolder.tv_product.setBackground(context.getResources().getDrawable(R.drawable.button_ju));
//        } else {
//            viewHolder.tv_product.setBackground(context.getResources().getDrawable(R.drawable.button_main));
//        }

        if ("1".equals(dataList.get(position).getTypeid())) {
            viewHolder.tv_product.setBackground(context.getResources().getDrawable(R.drawable.button_ju));
        } else if ("0".equals(dataList.get(position).getTypeid())) {
            viewHolder.tv_product.setBackground(context.getResources().getDrawable(R.drawable.button_main));
        } else if ("2".equals(dataList.get(position).getTypeid())) {
            viewHolder.tv_product.setBackground(context.getResources().getDrawable(R.drawable.buttom_green));
        }
        viewHolder.tv_product.setText(dataList.get(position).getPackage_cate());
        viewHolder.tv_sku_info.setText(dataList.get(position).getSku_info());
        viewHolder.tv_goods_type.setText("房间号：" + dataList.get(position).getRoom_number());
        viewHolder.tv_price.setText("¥ " + dataList.get(position).getPrice());
        viewHolder.tv_goods_number.setText("x" + dataList.get(position).getNums());

        return convertView;
    }

    class ProjectOrderViewHolder {
        ImageView iv_img;
        TextView tv_goods_name;
        TextView tv_sku_info;
        TextView tv_product;
        TextView tv_goods_type;
        TextView tv_price;
        TextView tv_goods_number;
    }
}
